<script>
export default {
  globalData: {
    apiUrl: 'http://vote.uue.cn/api'
  },
  onLaunch: function() {
    console.log('App Launch')
    const list = ['navigateTo', 'redirectTo', 'reLaunch', 'switchTab']
    list.forEach(item => { // 用遍历的方式分别为,uni.navigateTo,uni.redirectTo,uni.reLaunch,uni.switchTab这4个路由方法添加拦截器
      uni.addInterceptor(item, {
        invoke(e) { // 调用前拦截
          console.log(e)
          if (!uni.getStorageSync('token') && e.url !== '/pages/login/index') {
            uni.redirectTo({
              url: '/pages/login/index'
            })
            return false
          } else {
            return true
          }
        },
        fail(err) { // 失败回调拦截
          console.log(err)
        }
      })
    })
  },
  onShow: function() {
    console.log('App Show')
  },
  onHide: function() {
    console.log('App Hide')
  },
  methods: {
  }
}
</script>

<style>
body {
  background-color: #fbf9fe;
}
</style>
